package com.mask.im.server.netty.action.handler;

import com.mask.im.server.netty.enums.IMActionEnum;
import com.mask.im.server.netty.model.IMReceiveMessage;
import io.netty.channel.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * @className： MaskIMFriendActionHandler
 * @Description: 好友操作类
 * @Author：jian
 * @Date：2025/8/29 01:43
 */

@Log4j2
@Component
public class IMFriendActionHandler extends IMAbstractChatHandler {

    @Override
    public IMActionEnum getAction() {
        return IMActionEnum.FRIEND_ACTION;
    }


    @Override
    public void handle(IMReceiveMessage imReceiveMessage, Channel channel) {
//        Integer extend = imReceiveMessage.getExtend();
//        switch (null == extend ? 0 : extend) {
//            //发出请求
//            case 1:
//                handleFriendRequest(imReceiveMessage, channel);
//                break;
//            //同意请求
//            case 2:
//                handleRequestResponse(imReceiveMessage, channel);
//                break;
//            //拒绝请求
//            case 3:
//                break;
//
//        }
//    }

//    @Transactional
//    public void handleFriendRequest(IMReceiveMessage imReceiveMessage, Channel channel) {
//        //添加的好友id
//        Long receiverId = imReceiveMessage.getReceiverId();
//        //添加好友消息内容
//        Object message = imReceiveMessage.getContent();
//        //当前登录人id
//        Long userId = MaskSecurityUtil.getCurrentUserId();
//        //添加人不能是自己
//        if (receiverId.equals(userId)) {
//            //返回不能添加自己为好友
//        }
//
//        //查找现有的正常好友关系
//        IMFriendRelationDO friendRelation = new IMFriendRelationDO();
////        IMFriendRelationDO friendRelation = friendRelationService.getOne(new LambdaQueryWrapper<IMFriendRelationDO>()
////                .eq(IMFriendRelationDO::getFriendId, receiverId)
////                .eq(IMFriendRelationDO::getUserId, userId)
////                .eq(IMFriendRelationDO::getFriendStatus, 1));
//
//        if (friendRelation != null) {
//            throw new BusinessException("对方已在你的好友列表中");
//        }
//
//        //校验对方是否已将自己拉黑（B→A为黑名单）
////        IMFriendRelationDO reverseBlack = friendRelationService.getOne(
////                new LambdaQueryWrapper<IMFriendRelationDO>()
////                        .eq(IMFriendRelationDO::getUserId, receiverId)
////                        .eq(IMFriendRelationDO::getFriendId, userId)
////                        .eq(IMFriendRelationDO::getFriendStatus, 3)
////        );
//        IMFriendRelationDO reverseBlack = new IMFriendRelationDO();
//
//
//        if (reverseBlack != null) {
//            throw new BusinessException("对方已将你加入黑名单，无法申请");
//        }
//
//
//        //检查对方是否正在申请添加自己（处理双方同时申请的核心逻辑）
////        IMFriendApplicationDO targetApplyToMe = friendApplicationService.getOne(
////                new LambdaQueryWrapper<IMFriendApplicationDO>()
////                        .eq(IMFriendApplicationDO::getApplicantId, receiverId)
////                        .eq(IMFriendApplicationDO::getTargetUserId, userId)
////                        .eq(IMFriendApplicationDO::getApplyStatus, 0) // 0=待处理
////        );
//        IMFriendApplicationDO targetApplyToMe = new IMFriendApplicationDO();
//        if (targetApplyToMe != null) {
//            // 双方同时申请，直接建立双向好友关系
//            transactionTemplate.execute(status -> {
//                try {
//                    // 创建双向好友关系
//                    createMutualRelation(userId, receiverId);
//
//                    // 标记双方申请为已通过
//                    targetApplyToMe.setApplyStatus(1); // 1=已通过
//                    targetApplyToMe.setHandleTime(LocalDateTime.now());
////                    friendApplicationService.updateById(targetApplyToMe);
//                    return true;
//                } catch (Exception e) {
//                    status.setRollbackOnly();
//                    log.error("处理双方同时申请好友失败", e);
//                    return false;
//                }
//            });
////            return;
//        }
//
//
//        //校验是否有未处理的申请（A→B） 0=待处理，3=已过期（过期可重新申请）
////        IMFriendApplicationDO existApply = friendApplicationService.getOne(
////                new LambdaQueryWrapper<IMFriendApplicationDO>()
////                        .eq(IMFriendApplicationDO::getApplicantId, userId)
////                        .eq(IMFriendApplicationDO::getTargetUserId, receiverId)
////                        .in(IMFriendApplicationDO::getApplyStatus, 0, 3));
//
//        IMFriendApplicationDO existApply = new IMFriendApplicationDO();
//
//        if (existApply != null && existApply.getApplyStatus() == 0) {
//            throw new BusinessException("已有未处理的申请，请等待对方回复");
//        }
//
//
//        //校验对方是否已添加自己为好友（B→A为已通过）
////        IMFriendRelationDO reverseRelation = friendRelationService.getOne(
////                new LambdaQueryWrapper<IMFriendRelationDO>()
////                        .eq(IMFriendRelationDO::getUserId, receiverId)
////                        .eq(IMFriendRelationDO::getFriendId, userId)
////                        .eq(IMFriendRelationDO::getFriendStatus, 1)
////        );
//        IMFriendRelationDO reverseRelation = new IMFriendRelationDO();
//
//        if (reverseRelation != null) {
//            // 若对方已添加自己，直接建立双向关系
//            // 若对方已添加自己，直接建立双向关系
//            createMutualRelation(userId, receiverId);
////            return;
//        }
//
//        //创建新申请
//        IMFriendApplicationDO application = new IMFriendApplicationDO();
//        application.setApplicantId(userId);
//        application.setTargetUserId(receiverId);
//        application.setApplyMessage(Objects.isNull(message)?"":message.toString());
//        application.setApplyStatus(0); // 待处理
//        application.setExpireTime(LocalDateTime.now().plusDays(7)); // 7天过期
////        friendApplicationService.save(application);
//
////        Friendships friendships = friendshipsService.getOne(new LambdaQueryWrapper<Friendships>()
////                .eq(Friendships::getOneUserId, receiverId)
////                .eq(Friendships::getTwoUserId, userId));
//
//        Friendships friendships = new Friendships();
//        IMSendMessage websocketDTO = new IMSendMessage();
//        if (Objects.isNull(friendships)) {
//            Friendships isFriendship = new Friendships();
//
////            Friendships isFriendship = friendshipsService.getOne(new LambdaQueryWrapper<Friendships>()
////                    .eq(Friendships::getOneUserId, userId)
////                    .eq(Friendships::getTwoUserId, receiverId));
//            if (Objects.nonNull(isFriendship) && !isFriendship.getIsFriends().equals(CommonConstant.IS_FRIEND)) {
//                //检查是否两边同时发起申请添加
//                requestsOnBothSides(channel, receiverId, message, userId, isFriendship);
//            } else {
//                //对方没有申请方的好友关系
//                Friendships receiverFriendships = buildBaseFriendships(receiverId, userId, String.valueOf(message));
//                receiverFriendships.setIsFriends(CommonConstant.APPLYING);
////                friendshipsService.save(receiverFriendships);
//                websocketDTO.setCmd(WebSocketConstant.ADD_FRIEND_REQUEST_ADD);
//                websocketDTO.setMessage(message);
//                Channel userIdChannel = channelService.getUserIdChannel(receiverId.toString());
//                if (userIdChannel != null) {
//                    userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//                }
//            }
//
//        } else if (friendships.getIsFriends().equals(CommonConstant.IS_FRIEND) && friendships.getIsDelete().equals(0)) {
//            //对方含有申请方的关系
//            Date nowTime = new Date();
//            Friendships isFriendship = new Friendships();
//
////            Friendships isFriendship = friendshipsService.getOne(new LambdaQueryWrapper<Friendships>()
////                    .eq(Friendships::getOneUserId, userId)
////                    .eq(Friendships::getTwoUserId, receiverId));
//            if (Objects.isNull(isFriendship)) {
//                Friendships receiverFriendships = buildBaseFriendships(userId, receiverId, String.valueOf(message));
//                receiverFriendships.setIsFriends(CommonConstant.IS_FRIEND);
////                friendshipsService.save(receiverFriendships);
//            } else {
//                if (!isFriendship.getIsFriends().equals(CommonConstant.IS_FRIEND)) {
////                    friendshipsService.update(null, new LambdaUpdateWrapper<Friendships>()
////                            .set(Friendships::getIsFriends, CommonConstant.IS_FRIEND)
////                            .set(Friendships::getIsDelete, FALSE)
////                            .eq(Friendships::getOneUserId, userId)
////                            .eq(Friendships::getTwoUserId, receiverId));
//                } else {
////                    friendshipsService.update(null, new LambdaUpdateWrapper<Friendships>()
////                            .set(Friendships::getIsFriends, CommonConstant.IS_FRIEND)
////                            .set(Friendships::getIsDelete, FALSE)
////                            .eq(Friendships::getOneUserId, userId)
////                            .eq(Friendships::getTwoUserId, receiverId));
//                }
//            }
//            //封装响应消息
//            websocketDTO.setCmd(WebSocketConstant.SINGLE_CHAT);
//            websocketDTO.setMessage(message);
//            //保存聊天记录
//            Channel userIdChannel = channelService.getUserIdChannel(receiverId.toString());
//            IMFriendChatMessageDO friendChatMessage = saveChatStorage(receiverId, (String) message, userId, userIdChannel, 1, nowTime);
//            //获取聊天记录插入的
////            FriendChatMessageDTO friendChatMessageDTO = friendshipsService.getChatStorageDTO(friendChatMessage);
//            FriendChatMessageDTO friendChatMessageDTO = new FriendChatMessageDTO();
//            websocketDTO.setCmd(WebSocketConstant.SINGLE_CHAT);
//            websocketDTO.setMessage(friendChatMessageDTO);
//
//            if (userIdChannel != null) {
//                userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//            }
//            channel.write(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//            getListOfFriends(channel, receiverId, (String) message, userId, nowTime);
//
//        } else if (friendships.getIsFriends().equals(CommonConstant.REJECT) && friendships.getIsDelete().equals(0)) {
////            friendshipsService.update(null, new LambdaUpdateWrapper<Friendships>()
////                    .set(Friendships::getIsFriends, CommonConstant.APPLYING)
////                    .eq(Friendships::getOneUserId, friendships.getOneUserId())
////                    .eq(Friendships::getTwoUserId, friendships.getTwoUserId())
////                    .eq(Friendships::getIsFriends, CommonConstant.REJECT));
//            websocketDTO.setCmd(WebSocketConstant.ADD_FRIEND_REQUEST_ADD);
//            websocketDTO.setMessage(message);
//            Channel userIdChannel = channelService.getUserIdChannel(friendships.getOneUserId().toString());
//            if (userIdChannel != null) {
//                userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//            }
//
//        } else if (friendships.getIsDelete().equals(1)) {
//            Friendships isFriendship = new Friendships();
////
////            Friendships isFriendship = friendshipsService.getOne(new LambdaQueryWrapper<Friendships>()
////                    .eq(Friendships::getOneUserId, userId)
////                    .eq(Friendships::getTwoUserId, receiverId));
//            //表示对方也双方都申请添加对方
//            if (isFriendship.getIsFriends().equals(CommonConstant.APPLYING)) {
////                friendshipsService.update(null, new LambdaUpdateWrapper<Friendships>()
////                        .set(Friendships::getIsFriends, CommonConstant.IS_FRIEND)
////                        .set(Friendships::getIsDelete, 0)
////                        .eq(Friendships::getOneUserId, receiverId)
////                        .eq(Friendships::getTwoUserId, userId)
////                        .eq(Friendships::getIsDelete, 1));
//                Friendships requesterFriendships = new Friendships();
//
////                Friendships requesterFriendships = friendshipsService.getOne(new LambdaQueryWrapper<Friendships>()
////                        .eq(Friendships::getOneUserId, userId)
////                        .eq(Friendships::getTwoUserId, receiverId));
//                if (requesterFriendships.getIsDelete().equals(1)) {
////                    friendshipsService.update(null, new LambdaUpdateWrapper<Friendships>()
////                            .set(Friendships::getIsFriends, CommonConstant.IS_FRIEND)
////                            .set(Friendships::getIsDelete, 0)
////                            .eq(Friendships::getOneUserId, userId)
////                            .eq(Friendships::getTwoUserId, receiverId));
//                    Channel userIdChannel = channelService.getUserIdChannel(receiverId.toString());
//                    Date nowTime = new Date();
//                    saveChatStorage(receiverId, (String) message, userId, userIdChannel, 1, nowTime);
//                    saveChatStorage(userId, (String) message, receiverId, channel, 1, nowTime);
//                    if (userIdChannel != null) {
//                        getListOfFriends(userIdChannel, userId, (String) message, receiverId, nowTime);
//                    }
//                    getListOfFriends(channel, receiverId, (String) message, userId, nowTime);
//                }
//
//            } else {
////                friendshipsService.update(null, new LambdaUpdateWrapper<Friendships>()
////                        .set(Friendships::getIsFriends, CommonConstant.APPLYING)
////                        .eq(Friendships::getOneUserId, receiverId)
////                        .eq(Friendships::getTwoUserId, userId)
////                        .eq(Friendships::getIsDelete, 1));
//                websocketDTO.setCmd(WebSocketConstant.ADD_FRIEND_REQUEST_ADD);
//                websocketDTO.setMessage(message);
//                Channel userIdChannel = channelService.getUserIdChannel(receiverId.toString());
//                if (userIdChannel != null) {
//                    userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//                }
//            }
//        }
//    }
//
//    /**
//     * 创建双向好友关系（A→B 和 B→A）
//     */
//    private void createMutualRelation(Long userIdA, Long userIdB) {
//        // 创建 A→B 的关系
//        IMFriendRelationDO relationA = new IMFriendRelationDO();
//        relationA.setUserId(userIdA);
//        relationA.setFriendId(userIdB);
//        relationA.setFriendStatus(1); // 正常好友
////        friendRelationService.save(relationA);
//
//        // 创建 B→A 的关系（双向）
//        IMFriendRelationDO relationB = new IMFriendRelationDO();
//        relationB.setUserId(userIdB);
//        relationB.setFriendId(userIdA);
//        relationB.setFriendStatus(1); // 正常好友
////        friendRelationService.save(relationB);
//        //TODO 同步创建双方的单聊会话（chat_list）
//    }
//
//    private void handleRequestResponse(IMReceiveMessage imReceiveMessage, Channel channel) {
//        //接收用户id
//        AtomicReference<Boolean> flag = new AtomicReference<>(false);
//        Long receiverId = imReceiveMessage.getReceiverId();
//        Object message = imReceiveMessage.getContent();
//        Long userId = MaskSecurityUtil.getCurrentUserId();
//
//        //保存对方和自己的好友关系（此时的对方为请求者）
////        Friendships serviceOne = friendshipsService.getOne(new LambdaQueryWrapper<Friendships>()
////                .eq(Friendships::getOneUserId, receiverId)
////                .eq(Friendships::getTwoUserId, userId));
//        Friendships serviceOne = new Friendships();
//        //获取前面保存的好友关系（此时还未同意）
////        Friendships friendships = friendshipsService.getOne(new LambdaQueryWrapper<Friendships>()
////                .eq(Friendships::getOneUserId, userId)
////                .eq(Friendships::getTwoUserId, receiverId));
//        Friendships friendships = new Friendships();
//
//        if (friendships == null) {
//            return;
//        }
//
//        //将之前的表示进行确认为好友
//        friendships.setIsFriends(CommonConstant.IS_FRIEND);
//        friendships.setIsDelete(0);
//        friendships.setLatestNews((String) message);
//        friendships.setLatestTime(new Date());
//        Boolean execute = transactionTemplate.execute(status -> {
//            try {
//                //进行刷新好友关系
//                if (Objects.isNull(serviceOne)) {
//                    Friendships receiverFriendships = buildBaseFriendships(receiverId, userId, String.valueOf(message));
//                    receiverFriendships.setLatestNews((String) message);
//                    receiverFriendships.setLatestTime(new Date());
//                    receiverFriendships.setIsFriends(CommonConstant.IS_FRIEND);
////                    friendshipsService.save(receiverFriendships);
//                } else if (serviceOne.getIsDelete().equals(1)) {
//                    serviceOne.setIsDelete(0);
//                    serviceOne.setIsFriends(CommonConstant.IS_FRIEND);
//                    flag.set(true);
////                    friendshipsService.updateById(serviceOne);
//                }
////                friendshipsService.updateById(friendships);
//                return true;
//            } catch (Exception e) {
//                status.setRollbackOnly();
//                return false;
//            }
//        });
//
//        if (BooleanUtil.isTrue(execute)) {
//            //获取添加同意者的信息
//            IMFriendChatMessageDO friendChatMessage = deleteOriginalData(userId, receiverId, (String) message);
//            IMFriendChatMessageDO imFriendChatMessage = deleteOriginalData(receiverId, userId, friendships.getGuestBook());
//            FriendshipsDTO responders = getFriendshipsDTO(userId, receiverId);
//            if (channel != null) {
//                IMSendMessage websocketDTO = new IMSendMessage();
//                websocketDTO.setCmd(WebSocketConstant.ADD_FRIEND_RESPONSE_ADD);
//                websocketDTO.setMessage(responders);
//                channel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO, SerializerFeature.WriteMapNullValue)));
//            }
//            //获取添加请求者的信息
//            FriendshipsDTO requestor = getFriendshipsDTO(receiverId, userId);
//            Channel requestChannel = channelService.getUserIdChannel(receiverId.toString());
//            if (requestChannel != null && (Objects.isNull(serviceOne) || flag.get())) {
//                IMSendMessage websocketDTO = new IMSendMessage();
//                websocketDTO.setCmd(WebSocketConstant.ADD_FRIEND_RESPONSE_ADD);
//                websocketDTO.setMessage(requestor);
//                requestChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO, SerializerFeature.WriteMapNullValue)));
//            } else if (requestChannel != null) {
//                IMSendMessage websocketDTO = new IMSendMessage();
//                FriendChatMessageDTO friendChatMessageDTO1 = new FriendChatMessageDTO();
//                FriendChatMessageDTO friendChatMessageDTO2 = new FriendChatMessageDTO();
//
////                FriendChatMessageDTO friendChatMessageDTO1 = friendshipsService.getChatStorageDTO(friendChatMessage);
////                FriendChatMessageDTO friendChatMessageDTO2 = friendshipsService.getChatStorageDTO(imFriendChatMessage);
//                websocketDTO.setMessage(friendChatMessageDTO1);
//                websocketDTO.setCmd(WebSocketConstant.SINGLE_CHAT);
//                requestChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//            }
//        }
//    }
//
//    private void requestsOnBothSides(Channel channel, Long receiverId, Object message, Long userId, Friendships isFriendship) {
//        //首先判断自己是否持有对方的好友关系
//        //如果有则判断自己和对方关系是好友还是非好友
//        if (isFriendship.getIsFriends().equals(CommonConstant.APPLYING)) {
//            Date nowTime = new Date();
////            friendshipsService.update(null, new LambdaUpdateWrapper<Friendships>()
////                    .set(Friendships::getIsFriends, CommonConstant.IS_FRIEND)
////                    .set(Friendships::getIsDelete, 0)
////                    .eq(Friendships::getOneUserId, userId)
////                    .eq(Friendships::getTwoUserId, receiverId));
//            Friendships receiverFriendships = buildBaseFriendships(receiverId, userId, String.valueOf(message));
//            receiverFriendships.setIsFriends(CommonConstant.IS_FRIEND);
////            friendshipsService.save(receiverFriendships);
//            Channel userIdChannel = channelService.getUserIdChannel(receiverId.toString());
//            saveChatStorage(receiverId, (String) message, userId, userIdChannel, 1, nowTime);
//            saveChatStorage(userId, (String) message, receiverId, channel, 1, nowTime);
//            if (userIdChannel != null) {
//                getListOfFriends(userIdChannel, userId, (String) message, receiverId, nowTime);
//            }
//            getListOfFriends(channel, receiverId, (String) message, userId, nowTime);
//        }
//    }
//
//    private void getListOfFriends(Channel channel, Long receiverId, String message, Long userId, Date nowTime) {
//        changeRecentNews(receiverId, message, userId, nowTime);
//        //获取 对方含有申请方的关系 信息，并发送
//        FriendshipsDTO requestor = getFriendshipsDTO(userId, receiverId);
//        IMSendMessage requestorWebsocketDTO = new IMSendMessage();
//        requestorWebsocketDTO.setCmd(WebSocketConstant.ADD_FRIEND_RESPONSE_ADD);
//        requestorWebsocketDTO.setMessage(requestor);
//        channel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(requestorWebsocketDTO, SerializerFeature.WriteMapNullValue)));
//    }
//
//    public IMFriendChatMessageDO saveChatStorage(Long receiverId, String content, Long userId, Channel userIdChannel, int count, Date sendTime) {
//        IMFriendChatMessageDO imFriendChatMessage = IMFriendChatMessageDO.builder()
//                .senderId(userId)
//                .receiverId(receiverId)
//                .content(content)
//                .sendStatus(count == 0 ? 0 : 1)
//                .receiverDeleted(count == 0 ? false : true)
//                .createTime(sendTime)
//                .isRead(userIdChannel == null ? false : true)
//                .build();
////        imFriendChatMessageService.saveChat(imFriendChatMessage);
//        return imFriendChatMessage;
//    }
//
//    public void changeRecentNews(Long receiverId, String content, Long userId, Date sendTime) {
//        ArrayList<Friendships> friendships = new ArrayList<>();
////        List<Friendships> friendships = friendshipsService.list(new LambdaQueryWrapper<Friendships>()
////                .eq(Friendships::getOneUserId, userId).eq(Friendships::getTwoUserId, receiverId)
////                .or()
////                .eq(Friendships::getOneUserId, receiverId).eq(Friendships::getTwoUserId, userId));
//        friendships.forEach(item -> {
//            item.setLatestTime(sendTime);
//            item.setLatestNews(content);
////            friendshipsService.saveOrUpdate(item);
//        });
//    }
//
//    private Friendships buildBaseFriendships(Long oneUserId, Long twoUserId, String content) {
//        Friendships friendships = new Friendships();
//        friendships.setOneUserId(oneUserId);
//        friendships.setTwoUserId(twoUserId);
//        IMFriendGroupsDO fmyIMFriendGroups = new IMFriendGroupsDO();
////        IMFriendGroupsDO fmyIMFriendGroups = imFriendGroupsMapper.selectOne(new LambdaQueryWrapper<IMFriendGroupsDO>()
////                .eq(IMFriendGroupsDO::getUserInfoId, oneUserId)
////                .eq(IMFriendGroupsDO::getIsDefault, CommonConstant.DEFAULT_FRIEND));
//        if (Objects.isNull(fmyIMFriendGroups)) {
//            IMFriendGroupsDO imFriendGroups = IMFriendGroupsDO.builder()
//                    .groupName(CommonConstant.DEFAULT_FRIEND_GROUP_NAME)
//                    .isDefault(CommonConstant.DEFAULT_FRIEND)
//                    .sort(1)
//                    .userInfoId(oneUserId).build();
////            imFriendGroupsMapper.insert(imFriendGroups);
//            friendships.setGroupId(imFriendGroups.getId());
//        } else {
//            friendships.setGroupId(fmyIMFriendGroups.getId());
//        }
////        UserInfo userInfo = userInfoMapper.selectById(twoUserId);
//        UserInfo userInfo = new UserInfo();
//        friendships.setRemark(userInfo.getNickName());
//        friendships.setGuestBook(content);
//        return friendships;
//    }
//
//    private FriendshipsDTO getFriendshipsDTO(Long myUserInfoId, Long otherUserInfoId) {
////        FriendshipsDTO friendships = friendshipsService.getFriendshipsDTO(myUserInfoId, otherUserInfoId);
//        FriendshipsDTO friendships = new FriendshipsDTO();
//        Channel userIdChannel = channelService.getUserIdChannel(friendships.getFriendId().toString());
//        friendships.setType(1);
//        if (userIdChannel != null) {
//            friendships.setIsActive(1);
//        }
//        return friendships;
//    }
//
//    public IMFriendChatMessageDO deleteOriginalData(Long fromUserId, Long toUserId, String message) {
//        //删除前面
////		chatStorageMapper.delete(new LambdaQueryWrapper<IMFriendChatMessage>()
////				.eq(IMFriendChatMessage::getFromUserId, fromUserId)
////				.eq(IMFriendChatMessage::getToUserId, toUserId));
//        //加入第一条招呼
//        IMFriendChatMessageDO imFriendChatMessage = IMFriendChatMessageDO.builder()
//                .senderId(fromUserId)
//                .receiverId(toUserId)
//                .content(message)
//                .sendStatus(1)
//                .receiverDeleted(false)
//                .senderDeleted(false)
//                .isRead(false).build();
////        imFriendChatMessageService.saveChat(imFriendChatMessage);
//        return imFriendChatMessage;
//    }
    }
}
